﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Resources="clr-namespace:WpfRcp.Resources">
    
    <Resources:Double2PercentConverter x:Key="double2PercentConverter" />
    <Resources:DoubleToIntConverter x:Key="doubleToIntConverter" />
    
    <Style x:Key="SliderRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="IsTabStop" Value="false" />
        <Setter Property="Focusable" Value="false" />
        <Setter Property="Background" Value="{DynamicResource sliderBackgroundBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border CornerRadius="2" Background="Transparent" SnapsToDevicePixels="True" Margin="-3 0 0 0" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="HorizontalSliderThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Foreground" Value="{DynamicResource thumbNormalBrush}" />
        <Setter Property="Width" Value="10" />
        <Setter Property="Height" Value="20" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border BorderThickness="1" BorderBrush="#666666" CornerRadius="2"
                            Background="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Margin="0,-1,0,-1">
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Foreground" Value="{DynamicResource thumbMouseOverBrush}" />
                        </Trigger>
                        <Trigger Property="IsDragging" Value="true">
                            <Setter Property="Foreground" Value="{DynamicResource thumbDraggingBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Slider}">
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Margin" Value="1" />
        <Setter Property="Background" Value="{DynamicResource sliderBackgroundBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Slider}">
                    <Border Width="{TemplateBinding Width}" HorizontalAlignment="Left" VerticalAlignment="Top"
                            Padding="2" CornerRadius="3" Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <TickBar Grid.Row="0" Visibility="Collapsed" x:Name="TopTick" Width="4" Fill="Red"
                                    Placement="Top" />
                            <Canvas Grid.Row="1">
                                <Rectangle Visibility="Hidden"
                                        Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
                                        x:Name="PART_SelectionRange" Height="4.0" />
                            </Canvas>
                            <Track x:Name="PART_Track" Grid.Row="1">
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                            Command="{x:Static Slider.DecreaseLarge}" />
                                </Track.DecreaseRepeatButton>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                            Command="{x:Static Slider.IncreaseLarge}" />
                                </Track.IncreaseRepeatButton>
                                <Track.Thumb>
                                    <Thumb x:Name="Thumb" Style="{StaticResource HorizontalSliderThumbStyle}"
                                            Tag="{TemplateBinding Value}" />
                                </Track.Thumb>
                            </Track>
                            <TickBar Visibility="Collapsed" x:Name="BottomTick" Width="4" Grid.Row="2"
                                    Fill="{TemplateBinding Foreground}" Placement="Bottom" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TickPlacement" Value="TopLeft">
                            <Setter Property="Visibility" TargetName="TopTick" Value="Visible" />
                        </Trigger>
                        <Trigger Property="TickPlacement" Value="BottomRight">
                            <Setter Property="Visibility" TargetName="BottomTick" Value="Visible" />
                        </Trigger>
                        <Trigger Property="TickPlacement" Value="Both">
                            <Setter Property="Visibility" TargetName="TopTick" Value="Visible" />
                            <Setter Property="Visibility" TargetName="BottomTick" Value="Visible" />
                        </Trigger>
                        <Trigger Property="IsSelectionRangeEnabled" Value="true">
                            <Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--SLIDER WITH PERCENTAGE INDICATOR-->
    <Style x:Key="PercentHorizontalSliderThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Foreground" Value="{DynamicResource thumbNormalBrush}" />
        <Setter Property="Width" Value="32" />
        <Setter Property="Height" Value="20" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border BorderThickness="1" BorderBrush="#666666" CornerRadius="2"
                            Background="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Margin="0,-1,0,-1">
                        <Label Content="{TemplateBinding Tag, Converter={StaticResource double2PercentConverter}}"
                                Padding="0" Foreground="{DynamicResource PercentageColor}" Margin="0 -1 0 0"
                                VerticalAlignment="Center" HorizontalAlignment="Center">
                            <Label.LayoutTransform>
                                <RotateTransform Angle="0" />
                            </Label.LayoutTransform>
                        </Label>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Foreground" Value="{DynamicResource thumbMouseOverBrush}" />
                        </Trigger>
                        <Trigger Property="IsDragging" Value="true">
                            <Setter Property="Foreground" Value="{DynamicResource thumbDraggingBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="PercentSlider" TargetType="{x:Type Slider}">
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Margin" Value="1" />
        <Setter Property="Background" Value="{DynamicResource sliderBackgroundBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Slider}">
                    <Border Width="{TemplateBinding Width}" HorizontalAlignment="Left" VerticalAlignment="Top"
                            Padding="2" CornerRadius="3" Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <TickBar Grid.Row="0" Visibility="Collapsed" x:Name="TopTick" Width="4" Fill="Red"
                                    Placement="Top" />
                            <Canvas Grid.Row="1">
                                <Rectangle Visibility="Hidden"
                                        Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
                                        x:Name="PART_SelectionRange" Height="4.0" />
                            </Canvas>
                            <Track x:Name="PART_Track" Grid.Row="1">
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                            Command="{x:Static Slider.DecreaseLarge}" />
                                </Track.DecreaseRepeatButton>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                            Command="{x:Static Slider.IncreaseLarge}" />
                                </Track.IncreaseRepeatButton>
                                <Track.Thumb>
                                    <Thumb x:Name="Thumb" Style="{StaticResource PercentHorizontalSliderThumbStyle}"
                                            Tag="{TemplateBinding Value}" />
                                </Track.Thumb>
                            </Track>
                            <TickBar Visibility="Collapsed" x:Name="BottomTick" Width="4" Grid.Row="2"
                                    Fill="{TemplateBinding Foreground}" Placement="Bottom" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TickPlacement" Value="TopLeft">
                            <Setter Property="Visibility" TargetName="TopTick" Value="Visible" />
                        </Trigger>
                        <Trigger Property="TickPlacement" Value="BottomRight">
                            <Setter Property="Visibility" TargetName="BottomTick" Value="Visible" />
                        </Trigger>
                        <Trigger Property="TickPlacement" Value="Both">
                            <Setter Property="Visibility" TargetName="TopTick" Value="Visible" />
                            <Setter Property="Visibility" TargetName="BottomTick" Value="Visible" />
                        </Trigger>
                        <Trigger Property="IsSelectionRangeEnabled" Value="true">
                            <Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible" />
                        </Trigger>

                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{DynamicResource sliderDisabledBackgroundKey}" />
                            <Setter Property="BorderBrush" Value="{DynamicResource sliderDisabledBorderBrushKey}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--SLIDER WITH LINEAR INDICATOR-->
    <Style x:Key="LinearHorizontalSliderThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Foreground" Value="{DynamicResource thumbNormalBrush}" />
        <Setter Property="Width" Value="32" />
        <Setter Property="Height" Value="20" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border BorderThickness="1" BorderBrush="#666666" CornerRadius="2"
                            Background="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Margin="0,-1,0,-1">
                        <Label x:Name="Label"
                                Content="{TemplateBinding Tag, Converter={StaticResource doubleToIntConverter}}"
                                Padding="0" Foreground="{DynamicResource PercentageColor}" Margin="0 -1 0 0"
                                VerticalAlignment="Center" HorizontalAlignment="Center">
                            <Label.LayoutTransform>
                                <RotateTransform Angle="0" />
                            </Label.LayoutTransform>
                        </Label>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Foreground" Value="{DynamicResource thumbMouseOverBrush}" />
                        </Trigger>
                        <Trigger Property="IsDragging" Value="true">
                            <Setter Property="Foreground" Value="{DynamicResource thumbDraggingBrush}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" TargetName="Label"
                                    Value="{DynamicResource PercentageDisabledColor}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="LinearSlider" TargetType="{x:Type Slider}">
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Margin" Value="1" />
        <Setter Property="Background" Value="{DynamicResource sliderBackgroundBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Slider}">
                    <Border Width="{TemplateBinding Width}" HorizontalAlignment="Left" VerticalAlignment="Top"
                            Padding="2" CornerRadius="3" Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <TickBar Grid.Row="0" Visibility="Collapsed" x:Name="TopTick" Width="4" Fill="Red"
                                    Placement="Top" />
                            <Canvas Grid.Row="1">
                                <Rectangle Visibility="Hidden"
                                        Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
                                        x:Name="PART_SelectionRange" Height="4.0" />
                            </Canvas>
                            <Track x:Name="PART_Track" Grid.Row="1">
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                            Command="{x:Static Slider.DecreaseLarge}" />
                                </Track.DecreaseRepeatButton>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                            Command="{x:Static Slider.IncreaseLarge}" />
                                </Track.IncreaseRepeatButton>
                                <Track.Thumb>
                                    <Thumb x:Name="Thumb" Style="{StaticResource LinearHorizontalSliderThumbStyle}"
                                            Tag="{TemplateBinding Value}" />
                                </Track.Thumb>
                            </Track>
                            <TickBar Visibility="Collapsed" x:Name="BottomTick" Width="4" Grid.Row="2"
                                    Fill="{TemplateBinding Foreground}" Placement="Bottom" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TickPlacement" Value="TopLeft">
                            <Setter Property="Visibility" TargetName="TopTick" Value="Visible" />
                        </Trigger>
                        <Trigger Property="TickPlacement" Value="BottomRight">
                            <Setter Property="Visibility" TargetName="BottomTick" Value="Visible" />
                        </Trigger>
                        <Trigger Property="TickPlacement" Value="Both">
                            <Setter Property="Visibility" TargetName="TopTick" Value="Visible" />
                            <Setter Property="Visibility" TargetName="BottomTick" Value="Visible" />
                        </Trigger>
                        <Trigger Property="IsSelectionRangeEnabled" Value="true">
                            <Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{DynamicResource sliderDisabledBackgroundKey}" />
                            <Setter Property="BorderBrush" Value="{DynamicResource sliderDisabledBorderBrushKey}" />
                            <Setter Property="IsEnabled" TargetName="PART_Track" Value="False" />
                            <Setter Property="IsEnabled" TargetName="Thumb" Value="False" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>